<?php require_once ('../common/check.php');  //权限校验 ?>
<?php
    // 这里的查询主要是为了显示文章分类下拉列表
    require('../common/conn.php');
    $sql = "select * from category";
    $result= mysqli_query($link,$sql);
    if($result===false){ //表示执行的sql有错误sql
        exit;
    }
    // 将分类列表保存到cates变量中，供下拉列表使用
    $cates = mysqli_fetch_all($result,MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>后台管理系统</title>
		<link href="images/index.css" type="text/css" rel="stylesheet"/>
		<script src="images/jquery.js"></script>
	</head>
	<body>
    <?php require "top.php" ?>
		<section>
            <?php require "left.php" ?>
			<div class="mainbox">
				<div class="note">
					<h4><?=isset($id)?'编辑':'添加'?>文章</h4>
					<form action="article.php" method="post" enctype="multipart/form-data">
						<table class="news_form">
							<tr>
								<td>文章标题</td>
								<td><input type="text" name="title" value=<?=isset($row['title']) ? $row['title'] : ''?> class="inbox" /></td>
							</tr>
							<tr>
								<td>文章内容</td>
                                <td><textarea name="content" style="width: 50%" rows="5"><?=isset($row['content']) ? $row['content'] : ''?></textarea></td>
							</tr>
							<tr>
								<td>封面图片</td>
								<td><input type="file" name="img"/></td>
							</tr>
                            <tr>
                                <td>文章分类</td>
                                <td>
                                    <select name="category">
                                        <?php foreach($cates as $value):?>
                                        <option value=<?=isset($value['name']) ? $value['name'] : ''?>><?=isset($value['name']) ? $value['name'] : ''?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </td>
                            </tr>
							<tr>
								<td>
                                    <input type="hidden" name="id" value=<?=isset($row['id']) ? $row['id'] : ''?>>
                                    <input type="hidden" name="action" value=<?=isset($id) ? 'update' : 'insert'?>>
                                </td>
								<td><input type="submit" name="submit" value="提交"/></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</section>
		<script>
			$(function(){
				$('dt').click(function(){
					var obj=$(this).next();
					if($(this).next().css('display')=='block'){
						obj.hide('fast');
						$(this).removeClass('on');
					}else{
						obj.show('fast');
						$(this).addClass('on');
					}
				});
			});
		</script>
	</body>
</html>